<template>
	<view class="wrap">
		<view class="content">
			<block v-if="lists.length > 0">
				<view class="item" v-for="(item, index) in lists" :key="index">
					<view class="title">{{item.type == 1 ? '补卡' : item.type == 2 ? '请假' : item.type == 3 ? '出差' : item.type == 4 ? '外出' : item.type == 5 ? '加班' : '换班'}}申请</view>
					<block v-if="item.type != 1">
						<view class="label">
							<view class="text">开始时间：</view>
							<text>{{item.start_time_text}}</text>
						</view>
						<view class="label">
							<view class="text">结束时间：</view>
							<text>{{item.end_time_text}}</text>
						</view>
					</block>
					<block v-if="item.type == 1">
						<view class="label">
							<view class="text">补卡时间：</view>
							<text>{{item.start_time_text}}</text>
						</view>
					</block>
					<view class="label" v-if="item.type == 3">
						<view class="text">目的地：</view>
						<text>{{item.to_address}}</text>
					</view>
					<view class="label" v-if="item.type == 2">
						<view class="text">请假类型：</view>
						<text>{{item.type1}}</text>
					</view>
					<view class="label">
						<view class="text">申请理由：</view>
						<text>{{item.remark}}</text>
					</view>
					<view class="label" v-if="item.type == 1">
						<view class="text">图片：</view>
						<image :src="item.image" mode="widthFix"></image>
					</view>
					<view class="status">
						<text v-if="item.status == 1">待审批</text>
						<text v-else-if="item.status == 3" style="color: #F50C13;">领导审批拒绝</text>
						<text v-else-if="item.status == 7" style="color: #F50C13;">审核员审批拒绝</text>
						<text v-else-if="item.status == 10" style="color: #1A863B;">审批通过</text>
					</view>
				</view>
			</block>
			<u-empty v-else></u-empty>
		</view>
	</view>
</template>

<script>
import { getApplyLists } from '../../../api/manager';

	export default {
		data () {
			return {
				lists: [],
				page: 1,
				last_page: 1
			}
		},
		
		onLoad () {
			this.getData()
		},
		
		onReachBottom() {
			if(this.page == this.last_page){
				uni.showToast({
					title:'已经是最后一页了',
					icon:'none'
				})
			}else{
				this.page++
				this.getData()
			}
		},
		
		methods: {
			async getData () {
				if(this.page == 1){
					this.lists = []
				}
				let res = await getApplyLists({status: '3,7,10', page: this.page})
				this.last_page = res.data.last_page
				if (res.code == 1) {
					res.data.data.forEach((item,index) => {
						this.lists.push(item)
					})
				} else {
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		min-height: 100vh;
		height: fit-content;
		background-color: #F2F2F2;
		padding: 15px;
		box-sizing: border-box;
		
		.content {
			
			.item {
				padding: 12px;
				border-radius: 10px;
				background-color: #fff;
				box-sizing: border-box;
				margin-bottom: 15px;
				
				.title {
					font-size: 20px;
					font-weight: bold;
					margin-bottom: 10px;
				}
				
				.label {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 10px;
					
					.text {
						display: block;
						width: 30%;
						font-size: 16px;
						color:#666;
					}
					
					text {
						display: block;
						font-size: 16px;
						color:#666;
						flex: 1;
					}
					
					image {
						display: block;
						width: 65vw;
						border-radius: 10px;
					}
				}
				
				.status {
					display: flex;
					align-items: center;
					justify-content: flex-end;
					
					text {
						font-size: 16px;
						color: #F1721D;
					}
				}
			}
		}
	}
</style>